{% extends 'app_admin/admin_base.html' %}
{% load static %}
{% load i18n %}
{% block title %}站点设置{% endblock %}
{% block custom_element %}
<link href="{% static 'tagsInput/tagsinput.css' %}" rel="stylesheet" type="text/css"/>
{% endblock %}
{% block content %}
<div class="layui-card">
  <div class="layui-card-body">
    <div class="layui-card-header" style="margin-bottom: 10px;">
      <div class="layui-row">
          <span style="font-size:18px;">站点设置
          </span>
      </div>
    </div>
    <div class="layui-row">
        <div class="layui-tab">
          <ul class="layui-tab-title">
            <li class="layui-this">基础设置</li>
            <li>邮箱设置</li>
            <li>文档设置</li>
            <li>站点数据管理</li>
          </ul>
          <div class="layui-tab-content">
              <!-- 网站设置 -->
            <div class="layui-tab-item layui-show">
               <form class="layui-form" lay-filter="meta_config">
                   <div class="layui-card settings-card">
                    <div class="layui-card-header">站点元信息</div>
                    <div class="layui-card-body">
                      <!-- 站点名称 -->
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">站点名称</label>
                        <div class="layui-input-inline">
                          <input name="site_name" placeholder="请输入站点标题" class="layui-input" value="{% if site_name != None %}{{site_name}}{% endif %}"></input>
                        </div>
                      </div>
                      <!-- 站点子标题 -->
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">子标题</label>
                        <div class="layui-input-block">
                          <input name="site_sub_name" placeholder="请输入站点的子标题" class="layui-input" value="{% if site_sub_name != None %}{{site_sub_name}}{% endif %}"></input>
                        </div>
                      </div>
                      <!-- 站点关键词 -->
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-block">
                          <input name="site_keywords" placeholder="多个关键词请使用使用英文逗号,进行分隔" class="layui-input" value="{% if site_keywords != None %}{{site_keywords}}{% endif %}"></input>
                        </div>
                      </div>
                      <!-- 站点描述 -->
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">站点描述</label>
                        <div class="layui-input-block">
                          <input name="site_desc" placeholder="请用简短的文字描述你的觅思文档站点" class="layui-input" value="{% if site_desc != None %}{{site_desc}}{% endif %}"></input>
                        </div>
                      </div>
                      <!-- 备案号 -->
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">备案号</label>
                        <div class="layui-input-inline">
                          <input name="beian_code" placeholder="请输入网站的备案号" class="layui-input" value="{% if beian_code != None %}{{beian_code}}{% endif %}"></input>
                        </div>
                      </div>
                        <div><button id="updateMetaBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                   </div>
               </form>
                <!-- 首页模式 -->
                <form class="layui-form" lay-filter="index_mode_config">
                  <div class="layui-card settings-card">
                    <div class="layui-card-header">首页模板</div>
                    <div class="layui-card-body">
                      <!-- 首页文集排序 -->
                      <div class="layui-form-item">
                        <label class="layui-form-label">首页排序</label>
                        <div class="layui-input-inline">
                          {% if index_project_sort == '-1' %}
                          <input type="radio" name="index_project_sort"" value="1" title="升序" >
                          <input type="radio" name="index_project_sort" value="-1" title="降序" checked>
                          {% else %}
                          <input type="radio" name="index_project_sort"" value="1" title="升序" checked>
                          <input type="radio" name="index_project_sort" value="-1" title="降序" >
                          {% endif %}
                        </div>
                        <div class="layui-form-mid layui-word-aux">首页文集列表的排序方式</div>
                      </div>
                      <div><button id="updateIndexModeBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                  </div>
                </form>

                <form class="layui-form" lay-filter="siteCtrlConfig">
                   <div class="layui-card settings-card">
                    <div class="layui-card-header">站点管控</div>
                    <div class="layui-card-body">
                      <!-- 站点注册开关 -->
                      <div class="layui-form-item">
                        <label class="layui-form-label">禁止注册</label>
                        <div class="layui-input-inline">
                          <input type="checkbox" name="close_register" lay-skin="switch" lay-text="开启|关闭"  {% if close_register %}checked{% endif %}>
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启此选项将禁止新用户注册</div>
                      </div>
                      <!-- 站点强制登录开关 -->
                       <div class="layui-form-item">
                        <label class="layui-form-label">全站登录</label>
                        <div class="layui-input-inline">
                          <input type="checkbox" name="require_login" lay-skin="switch" lay-text="开启|关闭"  {% if require_login %}checked{% endif %}>
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启此选项，除注册、登录页面外的所有页面的访问都需要登录</div>
                      </div>
                      <!-- 站点注册码开关 -->
                      <div class="layui-form-item">
                        <label class="layui-form-label">启用注册码</label>
                        <div class="layui-input-inline">
                          <input type="checkbox" name="enable_register_code" lay-skin="switch" lay-text="开启|关闭"  {% if enable_register_code %}checked{% endif %}>
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启此选项，新用户注册将需要填写注册码</div>
                      </div>
                      <!-- 登录验证码开关 -->
                      <div class="layui-form-item">
                        <label class="layui-form-label">登录验证码</label>
                        <div class="layui-input-inline">
                          <input type="checkbox" name="enable_login_check_code" lay-skin="switch" lay-text="开启|关闭"  {% if enable_login_check_code %}checked{% endif %}>
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启此选项，登录将需要填写验证码</div>
                      </div>
                        <div><button id="updateCtrlBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                   </div>
                </form>

                <!-- 版本更新检测 -->
                <form class="layui-form" lay-filter="version_check_config">
                  <div class="layui-card settings-card">
                    <div class="layui-card-header">版本更新检测</div>
                    <div class="layui-card-body">
                    <div class="layui-form-item">
                      <label class="layui-form-label">禁止更新检测</label>
                      <div class="layui-input-inline">
                        <input type="checkbox" name="disable_update_check" lay-skin="switch" lay-text="开启|关闭"  {% if disable_update_check %}checked{% endif %}>
                      </div>
                      <div class="layui-form-mid layui-word-aux">开启后，后台将不会主动检测应用是否存在新的版本，默认关闭。</div>
                    </div>
                    <div><button id="updateVersionCheckBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                  </div>
                </form>
                <form class="layui-form" lay-filter="ad_config">
                  <div class="layui-card settings-card">
                    <div class="layui-card-header">页面信息块配置</div>
                    <div class="layui-card-body">
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">统计代码</label>
                        <div class="layui-input-block">
                          <textarea name="static_code" placeholder="如果需要调用第三方的统计功能，请将第三方统计工具代码输入至此，可以包含<script>标签" class="layui-textarea">{{static_code}}</textarea>
                        </div>
                      </div>

                       <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">广告位1</label>
                        <div class="layui-input-block">
                          <textarea name="ad_code" placeholder="如果需要在文档正文上方添加广告，请将广告相关代码输入至此，可以包含<script>标签" class="layui-textarea">{{ad_code}}</textarea>
                        </div>
                      </div>
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">广告位2</label>
                        <div class="layui-input-block">
                          <textarea name="ad_code_2" placeholder="此广告位位于文档下方、分享按钮上方，可以包含<script>标签" class="layui-textarea">{{ad_code_2}}</textarea>
                        </div>
                      </div>

                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">广告位3</label>
                        <div class="layui-input-block">
                          <textarea name="ad_code_3" placeholder="此广告位位于文档左侧目录栏下方，可以包含<script>标签" class="layui-textarea">{{ad_code_3}}</textarea>
                        </div>
                      </div>
                     <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">广告位4</label>
                        <div class="layui-input-block">
                          <textarea name="ad_code_4" placeholder="此广告位位于文档左侧目录栏上方，可以包含<script>标签" class="layui-textarea">{{ad_code_4}}</textarea>
                        </div>
                      </div>
                      <div><button id="updateAdBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                  </div>
                </form>

                <!-- 默认搜索方式 -->
                <form class="layui-form" lay-filter="search_config">
                  <div class="layui-card settings-card">
                    <div class="layui-card-header">站点搜索配置</div>
                    <div class="layui-card-body">
                      <div class="layui-form-item">
                        <label class="layui-form-label">搜索方式</label>
                        <div class="layui-input-block">
                          {% if search_type == '1' %}
                          <input type="radio" name="search_type"" value="0" title="精准搜索" >
                          <input type="radio" name="search_type" value="1" title="全文搜索" checked>
                          {% else %}
                          <input type="radio" name="search_type"" value="0" title="精准搜索" checked>
                          <input type="radio" name="search_type" value="1" title="全文搜索" >
                          {% endif %}
                        </div>
                      </div>
                      <div><button id="updateSearchBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                    </div>
                  </div>
                </form>
            </div>
              <!-- 网站设置结束 -->

              <!-- 邮箱设置 -->
            <div class="layui-tab-item">
                <form class="layui-form" lay-filter="emailConfig">
                  <!-- 邮箱开关 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">启用邮箱</label>
                    <div class="layui-input-inline">
                      <input type="checkbox" name="enable_email" lay-skin="switch" lay-text="开启|关闭"  {% if enable_email %}checked{% endif %}>
                    </div>
                    <div class="layui-form-mid layui-word-aux">开启此选项后还需进行邮箱信息配置</div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">发件邮箱</label>
                    <div class="layui-input-block">
                      <input type="email" name="send_emailer" class="layui-input" required value="{{emailer.value}}">
                    </div>
                  </div>

                   <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SMTP 主机</label>
                    <div class="layui-input-block">
                      <input type="text" name="smtp_host" class="layui-input" required value="{{email_host.value}}">
                    </div>
                  </div>

                    <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SMTP 端口</label>
                    <div class="layui-input-block">
                      <input type="number" name="smtp_port" class="layui-input" required value="{{email_port.value}}">
                    </div>
                  </div>

                   <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SMTP 用户名</label>
                    <div class="layui-input-block">
                      <input type="text" name="username" class="layui-input" required value="{{email_username.value}}">
                    </div>
                  </div>

                    <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SMTP 密码</label>
                    <div class="layui-input-block">
                      <input type="password" name="pwd" class="layui-input" required value="{{email_dec_pwd}}">
                    </div>
                  </div>

                    <div class="layui-form-item">
                    <label class="layui-form-label">使用SSL</label>
                    <div class="layui-input-block">
                      <input type="checkbox" name="smtp_ssl" lay-skin="switch" lay-text="开启|关闭"  {% if email_ssl.value %}checked{% endif %}>
                    </div>
                  </div>

                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <button class="pear-btn pear-btn-primary pear-btn-sm" type="button" id="updateEmailBtn">保存邮箱设置</button>
                      <button class="pear-btn pear-btn-primary pear-btn-sm" type="button" id="checkEmail">验证邮箱设置</button>
                    </div>
                  </div>
                </form>
            </div>
              <!-- 邮箱设置结束 -->

              <!-- 全局文档设置 -->
            <div class="layui-tab-item">
                <form class="layui-form" lay-filter="global_doc_config">
                <div class="layui-card settings-card">
                  <div class="layui-card-header">文集、文档配置</div>
                  <div class="layui-card-body">
                    <!-- 文集导出开关 -->
                   <div class="layui-form-item">
                    <label class="layui-form-label">文集下载</label>
                    <div class="layui-input-inline">
                      <input type="checkbox" name="enable_project_report" lay-skin="switch" lay-text="开启|关闭"  {% if enable_project_report %}checked{% endif %}>
                    </div>
                    <div class="layui-form-mid layui-word-aux">开启此选项，文集允许导出为EPUB和DOCX等格式文件以供下载，文集拥有者可进行进一步控制特定文集是否开放导出</div>
                  </div>

                  <!-- 图片缩略开关 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">图片缩略</label>
                    <div class="layui-input-inline">
                      <input type="checkbox" name="img_scale" lay-skin="switch" lay-text="开启|关闭"  {% if img_scale %}checked{% endif %}>
                    </div>
                    <div class="layui-form-mid layui-word-aux">开启后文档中的图片将显示为最大宽度350px的缩略图</div>
                  </div>
                  <hr>
                  <!-- 长代码展开 -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">长代码展开</label>
                    <div class="layui-input-inline">
                      <input type="checkbox" name="long_code" lay-skin="switch" lay-text="开启|关闭"  {% if long_code %}checked{% endif %}>
                    </div>
                    <div class="layui-form-mid layui-word-aux">文档页面代码块默认最高500px，超出将滚动显示，开启后代码块将按原高度显示。</div>
                  </div>
                  <div><button id="updateDocBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                  </div>
                </div>
                </form>

              <form class="layui-form" lay-filter="media_config">
                <div class="layui-card settings-card">
                  <div class="layui-card-header">素材配置</div>
                  <div class="layui-card-body">
                    <div class="layui-form-item" style="" id="role-user">
                      <label class="layui-form-label">图片大小</label>
                      <div class="layui-input-inline">
                          <div class="tagsinput-primary form-group">
                              <input class="layui-input" type="number" name="img_size" id="img_size" value="{% if img_size != '' %}{{img_size}}{% endif %}" placeholder="">
                          </div>
                      </div>
                      <div class="layui-form-mid layui-word-aux">默认限制图片大小10MB，单位MB</div>
                    </div>

                    <div class="layui-form-item" style="" id="role-user">
                      <label class="layui-form-label">附件格式</label>
                      <div class="layui-input-inline">
                          <div class="tagsinput-primary form-group">
                              <input name="attachment_suffix" id="attachment_suffix" class="tagsinput" data-role="tagsinput" value="{% if attachment_suffix != '' %}{{attachment_suffix}}{% endif %}" placeholder="不带.号的格式后缀">
                          </div>
                      </div>
                      <div class="layui-form-mid layui-word-aux">默认支持zip文件格式</div>
                    </div>

                    <div class="layui-form-item" style="" id="role-user">
                      <label class="layui-form-label">附件大小</label>
                      <div class="layui-input-inline">
                          <div class="tagsinput-primary form-group">
                              <input class="layui-input" type="number" name="attachment_size" id="attachment_size" value="{% if attachment_size != '' %}{{attachment_size}}{% endif %}" placeholder="">
                          </div>
                      </div>
                      <div class="layui-form-mid layui-word-aux">默认限制附件文件大小50MB，单位MB</div>
                    </div>
                    <div><button id="updateMediaBtn" type="button" class="pear-btn pear-btn-primary pear-btn-sm">更新</button></div>
                  </div>
                </div>
                </form>
            </div>

            <!-- 站点数据管理 -->
              <div class="layui-tab-item">
                <div class="layui-form">
                    <div class="layui-row">
                        <div style="float: left;">
                            <strong><img src="{% static '/icon_img/icon-data.svg' %}" style="width: 16px;" />{% trans "导出站点数据" %}</strong>
                            <p>{% trans "将站点数据导出为 json 格式文件，你可以通过此操作备份站点的数据" %}</p>
                        </div>
                        <div style="float: right;">
                            <button class="pear-btn pear-btn-normal" style="float: right;margin-left: 10px;" onclick="backupData()"><i class="layui-icon layui-icon-export"></i><u>{% trans "导出数据" %}</u></button>
                        </div>
                    </div>
                    <hr>
                    <div class="layui-row">
                      <div style="float: left;">
                          <strong><img src="{% static '/icon_img/icon-media.svg' %}" style="width: 16px;" />{% trans "导出站点媒体文件" %}</strong>
                          <p>{% trans "导出站点的媒体数据（图片、附件），你可以通过此操作备份站点的媒体文件" %}</p>
                      </div>
                      <div style="float: right;">
                          <button class="pear-btn pear-btn-normal" style="float: right;margin-left: 10px;" onclick="backupData('media')"><i class="layui-icon layui-icon-export"></i><u>{% trans "导出数据" %}</u></button>
                      </div>
                  </div>
                </div>
              </div>
              <!-- 站点数据管理结束 -->
          </div>
        </div>
    </div>
  </div>
</div>
{% endblock %}
{% block custom_script %}
<script src="{% static 'jquery/3.5.0/jquery.min.js' %}"></script>
<!-- <script src="{% static 'layui/layui.js' %}"></script> -->
<script src="{% static '/tagsInput/tagsinput.js' %}?version={{mrdoc_version}}" type="text/javascript" charset="utf-8"></script>
<script>
  $.ajaxSetup({
      data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
  });
  var form = layui.form;
  var element = layui.element;
  var layer = layui.layer;

  // 更新站点配置
  function updateConfig(data){
    $.ajax({
        url:"{% url 'site_config' %}",
        type:"post",
        data:{"data":JSON.stringify(data)},
        success:function(r){
          if(r.code === 0){
            layer.msg("更新成功")
          }else{
            layer.msg(r.data)
          }
        },
        error:function(){
          layer.msg("更新异常")
        }
      })
  }

  // 更新函数1 - 用于 type 为 basic 的输入框、单选框等配置项
  function updateFunc1(name){
    var data = form.val(name)
    // console.log(data)
    var data_list = []
    for(var key in data){
      var item = {'type':'basic','name':key,'value':data[key]}
      data_list.push(item)
    }
    // console.log(data_list)
    updateConfig(data_list)
  }

  // 更新站点元信息
  $("#updateMetaBtn").click(function(){
    updateFunc1(name="meta_config")
  })

  // 更新首页主题配置
  $("#updateIndexModeBtn").click(function(){
    // console.log(form.val('index_mode_config'))
    updateFunc1(name="index_mode_config")
  })

  // 更新站点管控配置
  function updateSiteCtrl(){
    var formdata = form.val('siteCtrlConfig');
    var data_list = [];
    if(formdata.close_register == undefined){
      data_list.push({'type':'basic','name':'close_register','value':null})
    }else{
      data_list.push({'type':'basic','name':'close_register','value':formdata.close_register})
    }
    if(formdata.require_login == undefined){
      data_list.push({'type':'basic','name':'require_login','value':null})
    }else{
      data_list.push({'type':'basic','name':'require_login','value':formdata.require_login})
    }
    if(formdata.enable_login_check_code == undefined){
      data_list.push({'type':'basic','name':'enable_login_check_code','value':null})
    }else{
      data_list.push({'type':'basic','name':'enable_login_check_code','value':formdata.enable_login_check_code})
    }
    if(formdata.enable_register_code == undefined){
      data_list.push({'type':'basic','name':'enable_register_code','value':null})
    }else{
      data_list.push({'type':'basic','name':'enable_register_code','value':formdata.enable_register_code})
    }
    updateConfig(data_list);
  };
  $("#updateCtrlBtn").click(function(){
    updateSiteCtrl()
  })

   // 更新广告块配置
  $("#updateAdBtn").click(function(){
    updateFunc1(name="ad_config")
  })

  // 更新版本检测配置
  function updateVersionCheck(){
    var data = {
      'type':'basic',
      'name':'disable_update_check'
    }
    if(form.val("version_check_config").disable_update_check == undefined){
      data['value'] = null
    }else{
      data['value'] = form.val("version_check_config").disable_update_check
    }
    // console.log(data)
    updateConfig([data])
  }
  $("#updateVersionCheckBtn").click(function(){
    updateVersionCheck()
  })

  // 更新搜索配置
  $("#updateSearchBtn").click(function(){
    updateFunc1(name="search_config")
  })

  // 更新邮箱配置
  $("#updateEmailBtn").click(function(){
    var form_data = form.val("emailConfig")
    // console.log(form_data)
    var data_list = []
    if(form_data.enable_email == undefined){
      data_list.push({'type':'basic','name':'enable_email','value':null})
    }else{
      data_list.push({'type':'basic','name':'enable_email','value':form_data.enable_email})
    }
    if(form_data.smtp_ssl == undefined){
      data_list.push({'type':'email','name':'smtp_ssl','value':null})
    }else{
      data_list.push({'type':'email','name':'smtp_ssl','value':form_data.smtp_ssl})
    }
    for(var key in form_data){
      if(key != 'enable_email' && key != 'smtp_ssl' ){
        var item = {'type':'email','name':key,'value':form_data[key]}
        data_list.push(item)
      }
    }
    // console.log(data_list)
    updateConfig(data_list)

  })

  // 验证邮箱配置
  function checkEmailConfig(){
    layer.open({
      type:1,
      title:"验证邮箱配置",
      content:"<div style='padding:10px;'>将以现有配置发送一封测试邮件给发件邮箱，以检测邮箱配置是否正确！</div>",
      btn:['发送','取消'],
      yes:function(){
        sendEmailTest();
      },
      btn2:function(){
        layer.closeAll();
      }
    })
  };
  // 发送测试邮件
  function sendEmailTest(){
    var emailData = form.val("emailConfig");
    // console.log(emailData)
    layer.load()
    $.ajax({
      url:'{% url "send_email_test" %}',
      method:'post',
      data:emailData,
      success:function(r){
        layer.closeAll()
        if(r.status){
          layer.msg("测试邮件发送成功",{icon:1})
        }else{
          layer.msg("测试邮件发送失败"+r.data,{icon:2})
        }
      },
      error:function(){
        layer.closeAll()
        layer.msg("测试邮件发送异常",{icon:2})
      }
    })
  };
  $("#checkEmail").click(function(){
    checkEmailConfig()
  })

  // 更新全局文集文档配置
  $("#updateDocBtn").click(function(){
    var form_data = form.val("global_doc_config")
    // console.log(form_data)
    var data_list = []
    if(form_data.enable_project_report == undefined){
      data_list.push({'type':'basic','name':'enable_project_report','value':null})
    }else{
      data_list.push({'type':'basic','name':'enable_project_report','value':form_data.enable_project_report})
    }
    if(form_data.img_scale == undefined){
      data_list.push({'type':'basic','name':'img_scale','value':null})
    }else{
      data_list.push({'type':'basic','name':'img_scale','value':form_data.img_scale})
    }
    if(form_data.long_code == undefined){
      data_list.push({'type':'basic','name':'long_code','value':null})
    }else{
      data_list.push({'type':'basic','name':'long_code','value':form_data.long_code})
    }

    updateConfig(data_list)
  });
  // 更新素材配置
  $("#updateMediaBtn").click(function(){
    // console.log(form.val('media_config'))
    var data_list = []
    var form_data = form.val('media_config')

    // console.log(form_data)
    for(var key in form_data){
      var item = {'type':'doc','name':key,'value':form_data[key]}
      data_list.push(item)
    }
    updateConfig(data_list)
    // console.log(data_list)
  })
    // 导出站点数据
  backupData = function(mode = 'data'){
    var layer_content;
    if(mode == 'data'){
      layer_content = "你正在导出站点数据至本地，根据站点的数据量大小，此操作可能会消耗一定时间，请耐心等待，不要关闭或刷新页面！"
    }else if(mode == 'media'){
      layer_content = "你正在导出站点媒体文件至本地，根据站点的数据量大小，此操作可能会消耗一定时间，请耐心等待，不要关闭或刷新页面！"
    }
    layer.open({
      title:"导出站点数据",
      content:layer_content,
      yes:function(){
        layer.load(1);
        $.ajax({
          url:"{% url 'admin_backup' %}",
          method:'POST',
          data:{mode:mode},
          success: function(r) {
            layer.closeAll()
            if(r.status){
              downloadZip(r.data)
            }else{
              layer.msg('导出站点数据失败:' + r.data);
            }
          },
          error: function(xhr, status, error) {
            layer.closeAll();
              layer.msg('导出站点数据请求异常:' + error);
          }
        })
      }
    })
  };
  //下载文件弹出框
  downloadZip = function(download_link){
        layer.open({
            type:1,
            title:"下载文件",
            area:"300px",
            id:"downloadMd",
            content:'<div style="margin:10px;"><p style="text-align:center;color:red;">请尽快下载，避免失效！</p><br><a class="layui-btn layui-btn-fluid download-md-link" href="'+ download_link + '" download="mrdoc_backup.zip" >点击下载文件(zip)</a></div>',
            //btn:['确定','取消'], //添加按钮
            //btnAlign:'c', //按钮居中
            success: function (layero, index) {
                $(layero).find('.download-md-link').click(function () {
                    layer.closeAll();
                })
        }
        })
    };
</script>
{% endblock %}